#include <iostream>
#include <algorithm>

using namespace std;
const int N = 5010;
struct node
{
	int cost;
	int volume;
}a[N];
bool cmp(const node& n1, const node& n2)
{
	return n1.cost < n2.cost;
}
int n, k;
int main()
{
	cin >> k >> n;
	for (int i = 1; i <= n; i++) cin >> a[i].cost >> a[i].volume;
	sort(a + 1, a + n + 1, cmp);
	int ret = 0;
	for (int i = 1; i <= n; i++)
	{
		int c = a[i].cost, v = a[i].volume;
		if (v >= k)
		{
			ret += k * c;
			break;
		}
		k -= v;
		ret += v * c;
	}
	cout << ret << endl;
	return 0;
}